<?php
session_start();
require('conn.php');
require('functions.php');
if($_SESSION['login']==1){
	_location("ucenter.php",301);
	exit;
}
$ip=GetIP();
$time=time();
// if($config['openreg']!==2){
	// _location("reg.php",301);
	// exit;
// }
if($config['openreg']==0){
		echo "<script>alert('注册关闭，请联系我们');location.href='reg.php'</script>";
		exit;		
}
//获取wgateid
$wgateid=guolv($_GET['wgateid']);
$verify=guolv($_GET['verify']);
//print_r($wgateid);

//注册
	$tj_id=guolv($_GET['uid']);
	if(is_numeric($tj_id)==false){
		$tj_id=0;//推荐人
	}
	
	$row=$mysql->query("select * from `userdata` where `wgateid`='{$wgateid}' limit 1");
	if(!$row){
		$arr=array(
			//'id'=>null,
			'tj_id'=>$tj_id,
			'phone'=>'',
			'pass'=>'123456',
			'money'=>$song,
			'money_all'=>$song,
			'wx'=>'',
			'realname'=>'',
			'alipay'=>'',
			'wgateid'=>$wgateid,
			'ip'=>$ip,
			'kou'=>100,
			'day'=>date("Y-m-d",time()),
			'time'=>time(),
		);
		$value=arr2s($arr);
		$mysql->query("insert into `userdata` {$value}");
		$id=mysql_insert_id();
		if($id!==0){
			$_SESSION['userdata']=$row[0];
			$_SESSION['userdata']['id']=$id;
			$_SESSION['login']=1;
			_location("{$site}/ucenter.php",301);
			exit;
		}
	}else{	
		//已经注册
		//登陆奖励
		$row_login_ip=$mysql->query("select * from `refererdata` where `uid`='{$row[0]['id']}' and `aid`='0' and `day`='{$day}' limit 1");
		if(!$row_login_ip){
			$mysql->query("insert into `refererdata` values(null,'{$row[0]['id']}','0','ID：{$row[0]['id']}用户登录','','{$config['daysong']}','','','{$ip}','{$day}','{$time}')");
			//加钱
			$mysql->query("update `userdata` set `money`=`money`+'{$config['daysong']}',`money_all`=`money_all`+'{$config['daysong']}' where `id` in({$row[0]['id']}) limit 1");					
		}
		
		$_SESSION['userdata']=$row[0];
		$_SESSION['login']=1;
		_location("{$site}/ucenter.php",301);
		exit;		
	}

?>